<template>
  <div id="btnCom">
    <el-popover placement="right"  v-model="visible"  width="500" trigger="click">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <div class="title">创建模型</div>
        <el-form-item label="展示名称" prop="name">
          <el-input
            v-model="ruleForm.name"
            placeholder="展示名称，如文章"
          ></el-input>
        </el-form-item>
        <el-form-item label="数据库名" prop="database">
          <el-input
            v-model="ruleForm.database"
            placeholder="数据库名，如article"
          ></el-input>
        </el-form-item>
        <el-form-item label="描述信息" prop="desc">
          <el-input
            type="textarea"
            v-model="ruleForm.desc"
            placeholder="描述信息，会展示在对应内容的管理页面顶部，可用于内容提示，支持 HTML 片段"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建时间（系统）字段名" prop="createtime">
          <el-input v-model="ruleForm.createtime"></el-input>
        </el-form-item>
        <el-form-item label="更新时间（系统）字段名" prop="updatetime">
          <el-input v-model="ruleForm.updatetime"></el-input>
        </el-form-item>

        <div class="button">
          <el-button @click="resetForm('ruleForm')">取消</el-button>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >创建</el-button>
        </div>
      </el-form>
      <el-button slot="reference" type="primary" icon="el-icon-plus"
        >新建模型</el-button>
    </el-popover>
  </div>
</template>

<script>
export default {
  name: "btnCom",
  data() {
    return {
      ruleForm: {
        name: "",
        database: "",
        desc: "",
        updatetime: "_updateTime",
        createtime: "_createTime",
      },
      visible: false,
      rules: {
        name: [{ required: true, message: "请输入展示名称", trigger: "blur" }],
        database: [
          { required: true, message: "请输入数据库名", trigger: "blur" },
        ],
        updatetime: [
          { required: true, message: "请输入创建时间字段名", trigger: "blur" },
        ],
        createtime: [
          { required: true, message: "请输入修改时间字段名", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
     resetForm(formName) {
        this.$refs[formName].resetFields();
        this.visible = false;
        // console.log(this.visible)
    }
  },
};
</script>

<style>
.el-popover {
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
}
.el-form-item__label {
  /* text-align: left; */
  float: none;
  word-break: break-word;
}
.el-form-item__content {
  margin-left: 0 !important;
}
</style>

<style lang="less" scoped>
// #btnCom {
//   cursor: pointer;
//   padding: 8px 15px;
//   margin: 0 10px;
//   background-color: #2575e6;
//   color: #fff;
//   border-radius: 5px;
// }
.title {
  font-size: 18px;
  padding-bottom: 10px;
  margin-bottom: 15px;
  border-bottom: 1px solid #f0f0f0;
}
.button{
  display: flex;
  justify-content: flex-end;
}
</style>
